package com.ruoyi.site.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.site.domain.UserAuths;
import com.ruoyi.site.service.IUserAuthsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户认证/多渠道登录Controller
 *
 * @author chuckeytang
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/site/user-auths")
public class UserAuthsController extends BaseController
{
    @Autowired
    private IUserAuthsService userAuthsService;

    /**
     * 查询用户认证/登录渠道列表
     */
    @PreAuthorize("@ss.hasPermi('site:userauths:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserAuths userAuths)
    {
        startPage();
        List<UserAuths> list = userAuthsService.selectUserAuthsList(userAuths);
        return getDataTable(list);
    }

    /**
     * 导出用户认证/登录渠道列表
     */
    @PreAuthorize("@ss.hasPermi('site:userauths:export')")
    @Log(title = "用户认证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserAuths userAuths)
    {
        List<UserAuths> list = userAuthsService.selectUserAuthsList(userAuths);
        ExcelUtil<UserAuths> util = new ExcelUtil<UserAuths>(UserAuths.class);
        util.exportExcel(response, list, "用户认证数据");
    }

    /**
     * 获取用户认证详细信息
     */
    @PreAuthorize("@ss.hasPermi('site:userauths:query')")
    @GetMapping(value = "/{authId}")
    public AjaxResult getInfo(@PathVariable("authId") Long authId)
    {
        return success(userAuthsService.selectUserAuthsByAuthId(authId));
    }

    /**
     * 新增用户认证
     */
    @PreAuthorize("@ss.hasPermi('site:userauths:add')")
    @Log(title = "用户认证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserAuths userAuths)
    {
        return toAjax(userAuthsService.insertUserAuths(userAuths));
    }

    /**
     * 修改用户认证
     */
    @PreAuthorize("@ss.hasPermi('site:userauths:edit')")
    @Log(title = "用户认证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserAuths userAuths)
    {
        return toAjax(userAuthsService.updateUserAuths(userAuths));
    }

    /**
     * 删除用户认证
     */
    @PreAuthorize("@ss.hasPermi('site:userauths:remove')")
    @Log(title = "用户认证", businessType = BusinessType.DELETE)
    @DeleteMapping("/{authIds}")
    public AjaxResult remove(@PathVariable Long[] authIds)
    {
        return toAjax(userAuthsService.deleteUserAuthsByAuthIds(authIds));
    }
}